package com.jin.vo;

import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.Mapper;
import org.springframework.data.domain.Page;

import java.util.ArrayList;
import java.util.List;

//继承泛型类，进行属性复制操作,T是没转化的（从数据里查出来的），K是要转化的VO
//既要分页，有要进行属性的复制
public class PagingDozer<T,k> extends Paging {
    public PagingDozer(Page<T> pageT,Class<k> kClass){
        this.initPageParameters(pageT);
        //拿到原始数据（没转化为VO的）
        List<T> tList = pageT.getContent();
        //获取复制属性的mapper,进行批量的赋值
        Mapper mapper = DozerBeanMapperBuilder.buildDefault();
        List<k> voList = new ArrayList<>();
        tList.forEach(t -> {
            k vo = mapper.map(t,kClass);
            voList.add(vo);
        });
        //这里面的voList已经有了复制的属性，直接返回就好
        this.setItems(voList);
    }
}
